package org.mock.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.mock.common.Condition;
import org.mock.dto.SabreHotelDetailDTO;
import org.mock.entity.SabreHotelDetail;
import org.mock.entity.TravelHotelDetail;
import org.mock.enums.SabreMockStateEnum;
import org.mock.mapper.SabreHotelDetailMapper;
import org.mock.mapper.TravelHotelDetailMapper;
import org.mock.service.SabreMockSceneService;
import org.mock.service.TravelHotelDetailService;
import org.mock.utils.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author AI
 * @since 2025-05-20
 */
@Service
@AllArgsConstructor
@Slf4j
public class TravelHotelDetailServiceImpl implements TravelHotelDetailService {

    protected TravelHotelDetailMapper travelHotelDetailMapper;
    private SabreMockSceneService sabreMockSceneService;

    @Override
    public SabreHotelDetailDTO handleRequest(JSONObject request) {
        log.info("[getHotelDetails] 请求：{}", request);
        SabreHotelDetailDTO dto = new SabreHotelDetailDTO();
        return dto;
    }

    @Override
    public SabreHotelDetailDTO handleQueryWrapper(SabreHotelDetailDTO dto) {
        String currentMockNo = sabreMockSceneService.getMockNoByStatus(SabreMockStateEnum.ON_REQUEST.getValue());
        return dto;
    }

    @Override
    public String handleData(TravelHotelDetail data, SabreHotelDetailDTO originalQuery) {
        if (ObjectUtil.isEmpty(data)) {
            log.info("暂无数据");
            return StrUtil.EMPTY;
        }
        String response = data.getResponse();
        return response;
    }

    @Override
    public TravelHotelDetail getOne(SabreHotelDetailDTO dto) {
        List<TravelHotelDetail> list = travelHotelDetailMapper.selectList(Condition.getQueryWrapper(BeanCopyUtils.copy(dto, TravelHotelDetail.class)));
        if (CollUtil.isEmpty(list)) {
            return null;
        } else {
            return list.get(0);
        }
//        return sabreHotelDetailMapper.selectOne(Condition.getQueryWrapper(BeanCopyUtils.copy(dto,SabreHotelDetail.class)));
    }
}
